package com.gxz.job.spring_boot_quartz;

import com.gxz.job.spring_boot_quartz.job.MyJob;
import com.gxz.job.spring_boot_quartz.job.MyJob2;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

    /**
     * 创建JobDetail，交由spring管理
     */
    @Bean
    public JobDetail jobDetail() {
        return JobBuilder.
                newJob(MyJob.class).
                withIdentity("myJob", "group1").
                storeDurably().
                build();
    }

    @Bean
    public Trigger trigger(@Qualifier("jobDetail") JobDetail jobDetail) {
        return TriggerBuilder.newTrigger().
                withIdentity("trigger1","group1").
                startNow().
                withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).
                forJob(jobDetail).
                build();
    }

    @Bean
    public JobDetail jobDetail2() {
        return JobBuilder.
                newJob(MyJob2.class).
                withIdentity("myJob2", "group1").
                storeDurably().
                build();
    }
    @Bean
    public Trigger trigger2(JobDetail jobDetail2) {
        return TriggerBuilder.newTrigger().
                withIdentity("trigger2","group1").
                startNow().
                withSchedule(CronScheduleBuilder.cronSchedule("0/3 * * * * ?")).
                forJob(jobDetail2).
                build();
    }
}
